home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
EyeBall.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
4KB
|
162 lines
" NAME EyeBall=manchester
AUTHOR TPH@cs.man.ac.uk
FUNCTION watches you at work
ST-VERSIONS 2.2
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE 10 Nov 1987
SUMMARY EyeBall
really does give you the feeling that you are being watched!
There are some examples for you to play with.(2.2). TPH
"!
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 10 November 1987 at 1:56:17 pm'!
!Point methodsFor: 'arithmetic'!
negated
^x negated @ y negated! !
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 10 November 1987 at 1:46:47 pm'!
Object subclass: #EyeBall
instanceVariableNames: 'eyePosition pupilPosition eyeDiameter pupilDiameter eyeForm pupilForm '
classVariableNames: ''
poolDictionaries: ''
category: 'Graphics-Games'!
!EyeBall methodsFor: 'accessing'!
eyeDiameter
"Answer with the overall diameter of the receiver."
^eyeDiameter!
eyeForm
"Answer with the form representing the main part of the receiver."
^eyeForm!
eyePosition
"Answer with a point representing the position of the receiver."
^eyePosition!
pupilDiameter
"Answer with the diameter of the receiver's pupil."
^pupilDiameter!
pupilForm
"Answer with the form representing the pupil of the receiver."
^pupilForm!
pupilPosition
"Answer with a point representing the position of the receiver's pupil."
^pupilPosition! !
!EyeBall methodsFor: 'modifying'!
updatePupil
"Update the receiver's pupil, if necessary. Answer true if
a change was made, otherwise false."
| newP diff sign |
diff _ (Sensor cursorPoint - eyePosition // 5).
sign _ (diff x sign)@(diff y sign).
newP _ eyePosition + ((diff abs min: (eyeDiameter // 3) asPoint) * sign).
newP = pupilPosition
ifTrue: [^false]
ifFalse: [pupilPosition _ newP. ^true]! !
!EyeBall methodsFor: 'displaying'!
display
"Display the receiver at its location, by creating an OpaqueFrom
appropriately and displaying it."
| tempForm opaqueForm |
tempForm _ (Form extent: self eyeForm extent) offset: self eyeForm offset.
pupilForm
displayOn: tempForm
at: tempForm offset negated + self pupilPosition - self eyePosition
rule: Form over.
eyeForm
displayOn: tempForm
at: tempForm offset negated
rule: Form and.
opaqueForm _ OpaqueForm figure: tempForm shape: self eyeForm.
opaqueForm displayAt: self eyePosition! !
!EyeBall methodsFor: 'private'!
setPosition: eyePos eyeDia: eyeD pupilDia: pupilD
"Initialise the instance variables, calculating the forms from
the diameters given."
eyePosition _ eyePos.
pupilPosition _ eyePos.
eyeDiameter _ eyeD.
eyeForm _ Form dotOfSize: eyeD.
pupilDiameter _ pupilD.
pupilForm _ Form dotOfSize: pupilD.! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EyeBall class
instanceVariableNames: ''!
!EyeBall class methodsFor: 'instance creation'!
position: eyePos eyeDia: eyeD pupilDia: pupilD
^self new setPosition: eyePos eyeDia: eyeD pupilDia: pupilD! !
!EyeBall class methodsFor: 'examples'!
exampleWorkspace1
"Select and execute the expressions here to create and
manipulate EyeBalls."
"
| eye |
eye _ EyeBall position: 100@100 eyeDia: 60 pupilDia: 42.
Smalltalk at: #EyeProcess put: [
[true] whileTrue: [
eye updatePupil ifTrue: [eye display].
(Delay forMilliseconds: 250) wait]] newProcess.
EyeProcess resume.
EyeProcess terminate.
Smalltalk removeKey: #EyeProcess.
ScheduledControllers restore.
Smalltalk garbageCollect.
"!
exampleWorkspace2
"Select and execute the expressions here to create and
manipulate EyeBalls."
"
| leftEye rightEye |
leftEye _ EyeBall position: 100@100 eyeDia: 30 pupilDia: 18.
rightEye _ EyeBall position: 150@100 eyeDia: 30 pupilDia: 18.
Smalltalk at: #EyeProcess put: [
[true] whileTrue: [
leftEye updatePupil ifTrue: [leftEye display].
rightEye updatePupil ifTrue: [rightEye display].
(Delay forMilliseconds: 250) wait]] newProcess.
EyeProcess resume.
EyeProcess terminate.
Smalltalk removeKey: #EyeProcess.
ScheduledControllers restore.
Smalltalk garbageCollect.
"! !